<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>sticky</title>
		<style>
			body {
				height: 20000px;
				width: 4000px;
			}

			#search {
				top: 10px;
				/*保证他距离上边距不会低于这个10px*/
				position: sticky;
				width: 300px;
				left: 300px;
				border: 1px solid red;
				/* margin: 0 auto; */
			}
		</style>
		<script>
			function isIE() {
				if (!!window.ActiveXObject || "ActiveXObject" in window)
					return true;
				else
					return false;
			}
			window.onload=function(){
				if(!isIE())
					return;
				var s=document.getElementById("search");
				s.style.marginLeft="300px";
			}
			window.onscroll=function(){
				if(!isIE())
					return;
				var s=document.getElementById("search");
				s.style.marginLeft="300px";
				let t=(document.documentElement||document.body).scrollTop;
				if(t>=210){
					s.style.marginLeft="0";
					s.style.position="fixed";
				}else{
					s.style.marginLeft="300px";
					s.style.position="static";
				}
			}
		</script>
	</head>
	<body>
		<div id="header" style="height: 200px;border: 2px solid darkred;"></div>
		<div id="search">
			<div>
				<form>
					<input type="text" name="wd" />
					<input type="submit" value="搜索" />
				</form>
			</div>
		</div>
	</body>
</html>
